package com.wxg.junit.appendix.B3;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

/**
 * {@link Factory}
 *
 * @author Wxg
 */
public class IsNotNullOrEmpty extends BaseMatcher<String> {

    @Override
    public boolean matches(Object item) {
        String str = (String) item;
        return (str != null) && !str.equals("");
    }

    @Override
    public void describeTo(Description description) {
        description.appendText("a string that is not null and not empty");
    }

    @Factory
    public static <T> Matcher<String> isNotNullOrEmpty() {
        return new IsNotNullOrEmpty();
    }

    @Factory
    public static <T> Matcher<String> notNullOrEmpty() {
        return new IsNotNullOrEmpty();
    }

}
